import router from "../router";
export function getChildrenPath () {
    let menus = JSON.parse(localStorage.getItem("menuList"))
    if(menus!=undefined&&menus!=''){
        menus.forEach(v => {
            v.children = routerChildren(v.children);
            v.component = routerCom(v.component);
        })
    }

    let rou = {
        path: '/',
        name: 'home',
        component: () => import('../components/main'),
        children: menus
    }
    router.addRoute(rou)
    //添加404
    let rou1= {
        path: '/404',
        component: () => import('@/views/404'),
        hidden: true
    }
    router.addRoute(rou1)
    const rou2= {
        path: '*',
        redirect: '/404',
        hidden: true
    }
    router.addRoute(rou2)
    //动态路由循环解析和添加

}

function routerCom(path) { //对路由的component解析
    return (resolve) => require([`@/views/${path}`], resolve);
}
function routerChildren(children) { //对子路由的component解析
    if (children != undefined&&children!=null) {
        children.forEach(v => {
            v.component = routerCom(v.component);
            if (v.children != undefined&&v.children!=null) {
                v.children = routerChildren(v.children)
            }
        })
    }
    return children
}

